import table from '@/components/dt/table/render.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
    {
      title: '提交人',
      field: 'userName',
      minWidth: 120,
      header: {
        filter: {
          key: 'userName',
          title: '提交人',
          input: {},
          placeholder: '请输入提交人名称或工号'
        }
      }
    },
    {
      title: '名片名称',
      field: 'userCardName',
      minWidth: 180
    },
    {
      title: '事业部',
      field: 'divisionName',
      minWidth: 120
    },
    {
      title: '分公司',
      field: 'companyName',
      minWidth: 120
    },
    {
      title: '事业处',
      field: 'officeName',
      minWidth: 120
    },
    {
      title: '案场',
      field: 'buildingName',
      minWidth: 120
    },
    {
      field: 'status',
      minWidth: 120,
      header: {
        filter: {
          title: '状态',
          key: 'status',
          placeholder: '请选择',
          select: {
            options: [{ key: 1, value: '已删除' }, { key: 2, value: '未删除' }]
          }
        }
      }
    },
    {
      title: '展示姓名',
      field: 'showName',
      minWidth: 120
    },
    {
      title: '展示手机号',
      field: 'phoneNumber',
      minWidth: 120
    },
    {
      title: '展示职位',
      field: 'positionName',
      minWidth: 120
    },
    {
      title: '展示邮箱',
      field: 'email',
      minWidth: 120
    },
    {
      title: '展示组织',
      field: 'ucompanyName',
      minWidth: 120
    },
    {
      field: 'auditStatus',
      minWidth: 130,
      header: {
        filter: {
          title: '审核状态',
          key: 'auditStatus',
          placeholder: '请选择',
          select: {
            key: 'processAuditStatus',
            multiple: true,
          }
        }
      }
    },
    {
      title: '名片发送次数',
      field: 'sendNumber',
      minWidth: 140,
      remoteSort: true,
    },
    {
      title: '名片访问人数',
      field: 'visitorPeopleNumber',
      minWidth: 140,
      remoteSort: true,
    },
    {
      title: '名片访问次数',
      field: 'visitorNumber',
      minWidth: 140,
      remoteSort: true,
    },
    {
      title: '名片转发次数',
      field: 'forwardNumber',
      minWidth: 140,
      remoteSort: true,
    },
    {
      minWidth: 160,
      header: {
        filter: dateOpt.range({
          title: '创建日期',
          startKey: 'startDate',
          endKey: 'endDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.startDate, val.endDate).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('创建日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.startDate, val.endDate).Y >= 2)
          }
        })
      },
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.createTime
          })
        }
      }
    },
    {
      title: '操作',
      fixed: 'right',
      minWidth: 150,
      align: 'center',
      slots: {
        default: (params, h) => {
          let btns = []
          btns.push({
            title: _this.unlocking('0212020100') ? '删除' : '',
            event: 'deleteFun',
            data: params.row
          })
          return table.cell.btns(_this, h, btns)
        }
      }
    }]
  }

}

export default Column